/**
 *    Copyright 2009-2015 the original author or authors.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package org.apache.ibatis.type;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 类型转换器,将JDBC之中的类型和java之中的类型进行转换 
 *  在这里分成两个部分的内容:
 *  [1]在预编译语句的时候,设置参数的时候需要使用到类型转换器
 *  [2]在结果集的返回的时候,需要使用类型转换器进行对象的类型的转换
 * @param <T>
 */
public interface TypeHandler<T> {
  
  /**
   * 为一个预编译的语句设置参数
   * @param ps
   * @param i  代表参数所在的位置
   * @param parameter 参数 
   * @param jdbcType  jdbc的类型
   * @throws SQLException
   */
  void setParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException;
  
  /**
   * 从结果集中通过列名类获取结果集
   * @param rs
   * @param columnName
   * @return
   * @throws SQLException
   */
  T getResult(ResultSet rs, String columnName) throws SQLException;
  
  /**
   * 通过索引来获取
   * @param rs
   * @param columnIndex
   * @return
   * @throws SQLException
   */
  T getResult(ResultSet rs, int columnIndex) throws SQLException;
  
  /**
   * 调用存储过程的时候,通过角标来获取结果
   * @param cs
   * @param columnIndex
   * @return
   * @throws SQLException
   */
  T getResult(CallableStatement cs, int columnIndex) throws SQLException;

}
